import { ApiProp } from "src/decorator/swagger";
import { classDto2Zod } from "src/utils";
import { z } from "zod";

/** 用户类型 */
export class UserDto {
  @ApiProp({ desc: 'id标识', zodType: z.number().int() })
  id!: number

  @ApiProp({ desc: '真实姓名' })
  realName!: string

  @ApiProp({ desc: '昵称' })
  nickName!: string

  @ApiProp({ desc: '头像url' })
  avatar!: string

  @ApiProp({ desc: '密码凭证(hash后的)' })
  psw!: string

  @ApiProp({ desc: '邮箱' })
  email!: string

  @ApiProp({ desc: '手机号' })
  phone!: string

  @ApiProp({ desc: '性别 0-女, 1-男, 2-未知', zodType: z.number().int() })
  sex!: number

  @ApiProp({ desc: '所属角色, 逗号分隔', zodType: z.array(z.string()).or(z.string())
    .transform(roleIds => (Object.prototype.toString.call(roleIds)==='[object String]') ? roleIds : (<Array<string>>roleIds).map(item=>item.trim()).join(','))
  })
  roleIds!: string

  @ApiProp({ desc: '是否启用' })
  isEnable!: boolean

  @ApiProp({ desc: '是否被删除' })
  isDeleted!: boolean

  @ApiProp({ desc: '创建时间', zodType: z.date().or(z.string())
    .transform(date => (Object.prototype.toString.call(date)==='[object Date]') ? date: new Date(date) )
  })
  createTime!: Date

  @ApiProp({ desc: '更新时间', zodType: z.date().or(z.string())
    .transform(date => (Object.prototype.toString.call(date)==='[object Date]') ? date: new Date(date) )
  })
  updateTime!: Date

  @ApiProp({ desc: 'uuid' })
  uuid!: string
}

/** 用户 */
export const UserZod = classDto2Zod(UserDto);
